//Math 
#include <iostream>
#define ll long long

using namespace std;

int main(){

	ll x,y;
	cin >> x >> y;
	
	ll c = 0;
	while(x && y){
		ll n;
		if(x > y){
			n = x / y;
			c += n * y * 4;
			x -= n * y;
		}else{
			n = y / x;
			c += n * x * 4;
			y -= n * x;
		}
	}
	
	cout << c;

	return 0;
}

